#----------------------------------------------
# Measuring Misperceptions: Limits of Party-Specific Stereotype Reports
# Orr and Huber, 2021, POQ
# Inputs: OrrHuber_POQ_Study1_raw.csv
# Outputs: OrrHuber_POQ_Study1_clean.csv
#----------------------------------------------



#----------------------------------------------
# Load Packages
#----------------------------------------------

library(dplyr)


#----------------------------------------------
# Load Data
#----------------------------------------------

dat <- read.csv("OrrHuber_POQ_Study1_raw.csv", as.is = TRUE)

dat <- rename(dat,
              "pid_vignette" = "YAL4_PERSON_PID",
              "infer_pid_rep" = "YAL418_1",
              "infer_pid_dem" = "YAL419_1",
              "infer_pid_ind" = "YAL420_1",
              "infer_rel_chr" = "YAL424_1",
              "infer_rel_jew" = "YAL425_1",
              "infer_rel_ath" = "YAL426_1",
              "infer_rel_oth" = "YAL427_1",
              "infer_rac_whi" = "YAL428_1",
              "infer_rac_bla" = "YAL429_1",
              "infer_rac_oth" = "YAL430_1")

dat$race <- recode(dat$race, "White" = "White", "Black" = "Black", .default = "Hisp_other")

dat$infer_pid_gap <- NA
dat$infer_pid_gap[dat$pid_vignette %in% "Democrat"] <- 100 - dat$infer_pid_dem[dat$pid_vignette %in% "Democrat"]
dat$infer_pid_gap[dat$pid_vignette %in% "Republican"] <- 100 - dat$infer_pid_rep[dat$pid_vignette %in% "Republican"]

dat$manip_pid100 <- dat$infer_pid_gap == 0
dat$manip_pid90 <- dat$infer_pid_gap <= 10

write.csv(dat, "OrrHuber_POQ_Study1_clean.csv", row.names = FALSE)
